Skip to content

Conversation

@andygrove
Copy link
Member

Summary

This PR replaces 6 dialect_of! macro invocations in the parser with dedicated Dialect trait methods. This improves the separation between generic parsing logic and dialect-specific behavior, making it easier for custom dialects to override behavior without modifying the parser.

Motivation

The codebase currently has ~134 dialect_of! macro calls scattered throughout the parser. The dialect module documentation already recommends using trait methods instead:

Note: when possible please the new style, adding a method to the Dialect trait rather than using this macro.

The benefits of adding a method on Dialect over this macro are:

  1. user defined Dialects can customize the parsing behavior
  2. The differences between dialects can be clearly documented in the trait

This PR is a proof-of-concept to gauge community interest before doing more of these refactorings.

Changes

New trait methods added to Dialect:

Method Dialects Description
supports_extract_comma_syntax() Snowflake, Generic EXTRACT(YEAR, d) comma syntax
supports_subquery_as_function_arg() Snowflake FLATTEN(SELECT ...) without extra parens
supports_create_view_comment_syntax() Snowflake, Generic CREATE VIEW ... COMMENT = '...'
supports_array_typedef_without_element_type() Snowflake ARRAY type without element specification
supports_parens_around_table_factor() Snowflake, Generic FROM (mytable) extra parens
supports_values_as_table_factor() Snowflake, Databricks, Generic FROM VALUES (1,'a') without parens

Each method includes documentation with examples and links to dialect documentation.

Test plan

  • All existing tests pass
  • cargo fmt and cargo clippy pass
  • No new tests needed as this is a refactoring of existing behavior

🤖 Generated with Claude Code

Replace 6 `dialect_of!` macro invocations in the parser with dedicated
Dialect trait methods. This improves the separation between generic
parsing logic and dialect-specific behavior, making it easier for
custom dialects to override behavior without modifying the parser.

New trait methods added:
- `supports_extract_comma_syntax()` - EXTRACT(YEAR, d) syntax
- `supports_subquery_as_function_arg()` - FLATTEN(SELECT ...) without parens
- `supports_create_view_comment_syntax()` - CREATE VIEW ... COMMENT = '...'
- `supports_array_typedef_without_element_type()` - ARRAY without element type
- `supports_parens_around_table_factor()` - FROM (mytable) extra parens
- `supports_values_as_table_factor()` - FROM VALUES (1,'a') without parens

This follows the guidance in the codebase: "when possible please use the
new style, adding a method to the Dialect trait rather than using this
macro."

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@andygrove andygrove requested a review from iffyio January 23, 2026 00:08
@andygrove
Copy link
Member Author

@alamb @iffyio could you let me know if you are open to me creating more PRs like this, using AI to fix up some tech debt? Thanks.

@andygrove andygrove changed the title Refactor: replace dialect_of! checks with Dialect trait methods Refactor: replace some dialect_of! checks with Dialect trait methods Jan 23, 2026
@iffyio
Copy link
Contributor

iffyio commented Jan 23, 2026

@alamb @iffyio could you let me know if you are open to me creating more PRs like this, using AI to fix up some tech debt? Thanks.

This sounds good to me thanks!

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @andygrove!

@iffyio iffyio added this pull request to the merge queue Jan 23, 2026
Merged via the queue into apache:main with commit abec6f9 Jan 23, 2026
10 checks passed
andygrove added a commit to andygrove/datafusion-sqlparser-rs that referenced this pull request Jan 23, 2026
Continues the work from apache#2171 by replacing 12 more `dialect_of!` macro
usages with proper `Dialect` trait methods. This allows user-defined
dialects to customize parsing behavior and makes the differences between
dialects more clearly documented in the trait.

New trait methods added:
- `supports_select_wildcard_replace` - SELECT * REPLACE syntax
- `supports_select_wildcard_ilike` - SELECT * ILIKE syntax
- `supports_select_wildcard_rename` - SELECT * RENAME syntax
- `supports_optimize_table` - OPTIMIZE TABLE statement
- `supports_install` - INSTALL statement
- `supports_detach` - DETACH statement
- `supports_prewhere` - PREWHERE clause
- `supports_with_fill` - WITH FILL in ORDER BY
- `supports_limit_by` - LIMIT BY clause
- `supports_interpolate` - INTERPOLATE clause
- `supports_settings` - SETTINGS clause
- `supports_select_format` - FORMAT clause in SELECT

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants